package com.ruicar.afs.cloud.basic.proceeds.mq.receiver.processor;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.ruicar.afs.cloud.basic.common.service.BasicReceiptRecordService;
import com.ruicar.afs.cloud.batch.service.AfsBatchInfoService;
import com.ruicar.afs.cloud.common.mq.finance.debit.dto.StartReceiptHandleDto;
import com.ruicar.afs.cloud.common.mq.rabbit.listener.AfsMqBizProcessor;
import com.ruicar.afs.cloud.common.mq.rabbit.message.MqTransCode;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-07-01 19:29
 */
@AllArgsConstructor
@Slf4j
@Component
public class StartReceiptHandleProcessor implements AfsMqBizProcessor<StartReceiptHandleDto> {

    private final BasicReceiptRecordService basicReceiptRecordService;
    private final AfsBatchInfoService afsBatchInfoService;


    public Date getBatchDate(){
        return DateUtil.parse(afsBatchInfoService.getSystemBatchInfo("icos").getBatchDate(), DatePattern.PURE_DATE_PATTERN);
    }



    @Override
    public boolean processMessage(StartReceiptHandleDto entity) throws Exception {
        return this.transData(entity);
    }

    @Override
    public MqTransCode getCode() {
        return MqTransCode.AFS_CONTRACT_FINANCE_BASIC_CONTRACT_START_RECEIPTHANDLE;
    }

    private boolean transData(StartReceiptHandleDto idList){
        return basicReceiptRecordService.handleReceiptByIdList(idList,getBatchDate());
    }
}
